/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.admin;

import controller.admin.*;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.validator.ValidatorException;
import javax.servlet.http.HttpServletRequest;
import model.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.faces.model.DataModel;
import org.hibernate.validator.internal.util.logging.Messages;
/**
 *
 * @author Administrator
 */
@ManagedBean(name = "amb")
@SessionScoped
public class ApplicantManagedBean implements Serializable {
    @EJB
    private ApplicantFacade applicantFacade;
    
    private Applicant a = new Applicant();

    Date date= new Date();

    public String getMessage() {
        return message;
    }
    private String message = new String();
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Applicant getA() {
        return a;
    }

    public void setA(Applicant a) {
        this.a = a;
    }


    public ApplicantFacade getApplicantFacade() {
        return applicantFacade;
    }

    public void setApplicantFacade(ApplicantFacade applicantFacade) {
        this.applicantFacade = applicantFacade;
    }


    public ApplicantManagedBean() {
    } 
    public String addapplicant(){
       String page ="Create";
       try{     
           this.a.setCreatedDate(new Date());
           this.a.setStatus(1);
           this.applicantFacade.create(this.a);
          
           page = "List";    
       }
        catch(Exception ex){
            System.out.println(ex.getMessage());
        }
       return page;
       
    }
    public String editApplicant(){
        this.applicantFacade.edit(this.a);
        return "List";
    }
    public String deleteAplicant(){
        String page = "";
        try {
            this.applicantFacade.remove(this.a);
        } catch (Exception e) {
            this.message ="Delete not found";
        }
        
        return "List";
    }
    public List<Applicant> applicantList(){
        return this.applicantFacade.findAll();
    }
    public String appEdit(Applicant app){
        this.a = app;
        return "Edit";
    }
    public String appView(Applicant app){
        this.a = app;
        return "View";
    }

}
